#include "Background.h"
#include "Configuration.h"

void Background::Display()
{
	for (int i = 0 ; i < Stars.size()-1 ; i++)
	{
		Stars[i].x -= 0.4f*(float)Config::GameSpeed;
		
		glEnable(GL_POINT_SMOOTH);
		glPointSize(StarSize[i]);
		glBegin(GL_POINTS);		
		glColor4f(1.0f,1.0f,1.0f,(float)(rand()%100)/100);
		glVertex3f(Stars[i].x,Stars[i].y,Stars[i].z);
		glEnd();
		glDisable(GL_POINT_SMOOTH);
		glPointSize(1.0);
		if (Stars[i].x < -Config::TopRightCorner.x)
		{
			Stars.erase(Stars.begin() + i);
			StarSize.erase(StarSize.begin() + i);
			Point star;
			star.x = Config::TopRightCorner.x + 20;
			star.y = -Config::TopRightCorner.y + rand()%(int)(2*Config::TopRightCorner.y);
			star.z = -100 - rand()%50;
			Stars.push_back(star);
			StarSize.push_back(rand()%4+1);
		}
	}
};

void Background::Initialise()
{
	_starsConcentration = 1;
	for (int i = 0 ; i < 2*Config::TopRightCorner.x ; i++)
		for (int j = 0 ; j < _starsConcentration-(rand()%_starsConcentration/10) ; j++)
		{
			Point star;
			star.x = -Config::TopRightCorner.x + i;
			star.y = -Config::TopRightCorner.y + rand()%(int)(2*Config::TopRightCorner.y);
			star.z = -100 - rand()%50;
			Stars.push_back(star);
			StarSize.push_back(rand()%4+1);
		}
};